package com.bjpowernode.core.schedule;

import com.bjpowernode.DlykServerApplication;
import com.bjpowernode.common.constant.DicEnum;
import com.bjpowernode.entity.TDicType;
import com.bjpowernode.entity.TProduct;
import com.bjpowernode.service.DicTypeService;
import com.bjpowernode.service.ProductService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@EnableScheduling
@RequiredArgsConstructor
@Slf4j
public class DataTask {

    //创建定时任务，查出字典，汽车存到缓存中
    private final DicTypeService dicTypeService;

    private final ProductService productService;

    //暂时先注销掉，不注销控制台不好查，等需要excel导入的时候再打开这个功能
    @Scheduled(cron = "0/3 * * * * ?")
    public void task() {
//        log.info("定时任务执行了" + new Date());
        List<TDicType> dicTypeList = dicTypeService.getDicTypeList();

        for (TDicType dicType : dicTypeList) {
            DlykServerApplication.cacheMap.put(dicType.getTypeCode(), dicType.getDicValueList());
        }

        List<TProduct> productList = productService.getProductList();
        DlykServerApplication.cacheMap.put(DicEnum.INTENTIONPRODUCT.getCode(), productList);

    }

}
